package model;

import java.io.Serializable;

import javax.persistence.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the projections database table.
 * 
 */
@Entity
@Table(name = "projections")
@NamedQueries({ 
	@NamedQuery(name = "Projection.findAll", query = "SELECT p FROM Projection p"),
	@NamedQuery(name = "getProjectionsByMovieId", query = "SELECT p.projections FROM Movie p WHERE p.id = :id"),
// @NamedQuery(name="Projection.findAllCinema",
// query="SELECT p FROM Projection p WHERE p.cinema.id= :cinemaId ORDER BY p.date")
})
public class Projection implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(unique = true, nullable = false)
	private int id;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private Date date;

	@Column(nullable = false, precision = 10, scale = 2)
	private BigDecimal price;

	// bi-directional many-to-one association to Cinema
	@ManyToOne
	@JoinColumn(name = "cinema_id", nullable = false)
	private Cinema cinema;

	// bi-directional many-to-one association to Movie
	@ManyToOne
	@JoinColumn(name = "movie_id", nullable = false)
	private Movie movie;

	// bi-directional many-to-one association to Seat
	@OneToMany(mappedBy = "projection")
	private List<Seat> seats;

	public Projection() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public Cinema getCinema() {
		return this.cinema;
	}

	public void setCinema(Cinema cinema) {
		this.cinema = cinema;
	}

	public Movie getMovie() {
		return movie;
	}

	public void setMovie(Movie movie) {
		this.movie = movie;
	}

	public List<Seat> getSeats() {
		return this.seats;
	}

	public void setSeats(List<Seat> seats) {
		this.seats = seats;
	}

	public Seat addSeat(Seat seat) {
		getSeats().add(seat);
		seat.setProjection(this);

		return seat;
	}

	public Seat removeSeat(Seat seat) {
		getSeats().remove(seat);
		seat.setProjection(null);

		return seat;
	}

}